<?php

namespace App\Http;

use App\Http\Middleware\ApiAccessLog;
use App\Http\Middleware\Applet\DouyinAppletRequest;
use App\Http\Middleware\AppletAuth;
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\CustomerThrottleRequests;
use App\Http\Middleware\DyWaiMaiCheckSign;
use App\Http\Middleware\ElmWaiMaiCheckSign;
use App\Http\Middleware\JwtAuth;
use App\Http\Middleware\MerchantBrandShop;
use App\Http\Middleware\MerchantUserPermission;
use App\Http\Middleware\MtWaiMaiCheckSign;
use App\Http\Middleware\PayCallbackAfter;
use App\Http\Middleware\RedirectIfAuthenticated;
use App\Http\Middleware\WaiMaiCallbackAfter;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
use Illuminate\Auth\Middleware\RequirePassword;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Http\Middleware\SetCacheHeaders;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Routing\Middleware\ValidateSignature;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        // \App\Http\Middleware\TrustHosts::class,
        \App\Http\Middleware\TrustProxies::class,
        \Fruitcake\Cors\HandleCors::class,
        \App\Http\Middleware\PreventRequestsDuringMaintenance::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        // \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            // 'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth'                       => Authenticate::class,
        'auth.basic'                 => AuthenticateWithBasicAuth::class,
        'cache.headers'              => SetCacheHeaders::class,
        'can'                        => Authorize::class,
        'guest'                      => RedirectIfAuthenticated::class,
        'password.confirm'           => RequirePassword::class,
        'signed'                     => ValidateSignature::class,
        'throttle'                   => ThrottleRequests::class,
        'verified'                   => EnsureEmailIsVerified::class,
        "jwtAuth"                    => JwtAuth::class,
        "AppletAuth"                 => AppletAuth::class,
        "DouyinAppletRequest"        => DouyinAppletRequest::class,
        'payCallback'                => PayCallbackAfter::class,
        'MtWaiMaiCheckSign'          => MtWaiMaiCheckSign::class,
        'ElmWaiMaiCheckSign'         => ElmWaiMaiCheckSign::class,
        'DyWaiMaiCheckSign'          => DyWaiMaiCheckSign::class,
        'WaiMaiCallbackAfter'        => WaiMaiCallbackAfter::class,
//        "merchantJwtAuth"     => \App\Http\Middleware\MerchantJwtAuth::class,
        'merchantUserPermission'     => MerchantUserPermission::class,
        'merchantBrandShop'          => MerchantBrandShop::class,
        'ApiAccessLog'               => ApiAccessLog::class,

        // 通用中间件
        'common.headerAuth'          => \App\Http\Middleware\Common\HeaderAuth::class, // 校验 header 头
        'common.userPermissionAuth'  => \App\Http\Middleware\Common\UserPermissionAuth::class, // 校验用户权限

        // POS 中间件
        'pos.shopStatusAuth'         => \App\Http\Middleware\Pos\ShopStatusAuth::class, // 校验 店铺状态
        'pos.shopStatusOrderAuth'    => \App\Http\Middleware\Pos\ShopStatusOrderAuth::class, // 校验 店铺可下单状态

        // WEB 中间件
//        'web'

        // 小程序中间件
        'applet.shopStatusOrderAuth' => \App\Http\Middleware\Applet\ShopStatusOrderAuth::class, // 校验 店铺可下单状态

        'customerThrottle' => CustomerThrottleRequests::class,

    ];
}
